import requests
import winsound
import bot
import time

url = "https://www.baidu.com/"
headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36 Edg/103.0.1264.49"}

resp = requests.get(url)
# print(resp.text)


def check_flag():
    try:
        r = requests.get(url, timeout=500)
        if(r.status_code != 200):
            return False
        else:
            return True
    except requests.exceptions.RequestException:
        return False


cnt = 0
while(1):
    time.sleep(3)
    timer = time.strftime('%H:%M:%S', time.localtime())
    if(check_flag() and check_flag() and check_flag()):
        cnt += 3
        winsound.Beep(1000, 1000)
        print("succeed" + " -- " + timer + "第" + str(cnt) + "次请求")
        bot.main()
    else:
        winsound.Beep(500, 1000)
        print("fail" + " -- " + timer + "第" + str(cnt) + "次请求")
